2024-10-03

Assignment

  • Create a web page presentation using R Markdown that features a plot created with Plotly. Host your webpage on either GitHub Pages, RPubs, or NeoCities. Your webpage must contain the date that you created the document, and it must contain a plot created with Plotly. We would love to see you show off your creativity.

The data set under consideration and goal

  • Consider the pre-loaded data set “EuStockMarkets” consisting of daily closing prices of major European stock indices, 1991-1998. The markets of interest are DAX, SMI, CAC, and FTSE.

  • We wish to determine a linear model for DAX given SMI, CAC, and FTSE as covariates.

A quick look at the dataset

data(EuStockMarkets)
EuStockMarkets <- as.data.frame(EuStockMarkets)
head(EuStockMarkets)
##       DAX    SMI    CAC   FTSE
## 1 1628.75 1678.1 1772.8 2443.6
## 2 1613.63 1688.5 1750.5 2460.2
## 3 1606.51 1678.6 1718.0 2448.2
## 4 1621.04 1684.1 1708.1 2470.4
## 5 1618.16 1686.6 1723.1 2484.7
## 6 1610.61 1671.6 1714.3 2466.8

Model selection

  • By the following nested likelihood ratio test, FTSE is not a significant covariate.
## Analysis of Variance Table
## 
## Model 1: DAX ~ 1
## Model 2: DAX ~ SMI
## Model 3: DAX ~ SMI + CAC
## Model 4: DAX ~ SMI + CAC + FTSE
##   Res.Df        RSS Df  Sum of Sq          F Pr(>F)    
## 1   1859 2187625263                                    
## 2   1858   38532840  1 2149092423 179597.275 <2e-16 ***
## 3   1857   22217334  1   16315505   1363.469 <2e-16 ***
## 4   1856   22209221  1       8113      0.678 0.4104    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The linear model

  • Therefore we predict DAX with SMI and CAC.
  • The coefficients and standard error are shown.
fit <- lm(DAX ~ SMI + CAC, data=EuStockMarkets)
fit$coefficients
##  (Intercept)          SMI          CAC 
## -210.2306616    0.4807757    0.5016909
summary(fit)$sigma
## [1] 109.3805

A 3d scatter plot

library(plotly)
plot_ly(EuStockMarkets, x = ~SMI, y = ~CAC, z = ~DAX)

A 2d scatter plot

plot_ly(EuStockMarkets, x = ~SMI, y = ~CAC, color = ~DAX)